package com.lmh.graphdisease.repository;

import com.lmh.graphdisease.entity.DiseaseEntity;
import org.neo4j.driver.internal.value.NodeValue;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.zip.DeflaterInputStream;

/**
 * @author lmh
 * @desc
 * @date 2023/3/6
 */
@Repository
public interface DiseaseRepository extends Neo4jRepository<DiseaseEntity,Long> {

    DiseaseEntity findDiseaseEntityByName(String name);


    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 当前疾病的并发症
     */
    @Query("MATCH(n:Disease)-[r:acompany_with]->(nn:Disease) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getAcompanyWith(String name,int num);


    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 查找当前疾病需要的所有检查项目
     */
    @Query("MATCH(n:Disease)-[r:need_check]->(nn:Check) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getNeedCheck(String name, int num);


    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 查找当前疾病不能吃什么
     */
    @Query("MATCH(n:Disease)-[r:no_eat]->(nn:Food) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getNoEat(String name,int num);


    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 查找当前疾病可以吃什么
     */
    @Query("MATCH(n:Disease)-[r:do_eat]->(nn:Food) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getDoEat(String name,int num);

    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 查找当前疾病建议吃什么
     */
    @Query("MATCH(n:Disease)-[r:recommand_eat]->(nn:Food) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getRecommandEat(String name,int num);


    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 当前疾病建议使用的药物
     */
    @Query("MATCH(n:Disease)-[r:recommand_drug]->(nn:Drug) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getRecommandDrug(String name,int num);


    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 当前疾病的常用药物
     */
    @Query("MATCH(n:Disease)-[r:common_drug]->(nn:Drug) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getCommonDrug(String name,int num);


    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 获取当前疾病的症状
     */
    @Query("MATCH(n:Disease)-[r:has_symptom]->(nn:Symptom) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getHasSymptom(String name,int num);


    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 获得所属科室
     */
    @Query("MATCH(n:Disease)-[r:belongs_to]->(nn:Department) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getBelongTo(String name,int num);


    @Query("MATCH (n:Disease) RETURN n SKIP $0 LIMIT $1")
    List<DiseaseEntity> getNumDisease(int page,int size);

    /**
     *@author lmh
     *@date 2023/3/27
     *@desc 根据关系，找出疾病
     */
    @Query("MATCH(n:Disease)-[r:has_symptom]->(nn:Symptom) WHERE nn.name = $0  RETURN n LIMIT $1")
    List<DiseaseEntity> getSymptomDisease(String symptomName,int num);

    @Query("MATCH(n:Disease)-[r:recommand_drug]->(nn:Drug) WHERE nn.name = $0 RETURN n LIMIT $1")
    List<DiseaseEntity> getDrugRecommandDisease(String drugname,int num);

    @Query("MATCH(n:Disease)-[r:common_drug]->(nn:Drug) WHERE nn.name = $0 RETURN n LIMIT $1")
    List<DiseaseEntity> getDrugCommonDisease(String drugname,int num);

    @Query("MATCH(n:Disease)-[r:need_check]->(nn:Check) WHERE nn.name = $0 RETURN n LIMIT $1")
    List<DiseaseEntity> getCheckDisease(String checkName,int num);

    @Query("MATCH(n:Disease)-[r:do_eat]->(nn:Food) WHERE nn.name = $0 RETURN n LIMIT $1")
    List<DiseaseEntity> getDoFoodDisease(String foodName,int num);

    @Query("MATCH(n:Disease)-[r:belongs_to]->(nn:Department) WHERE nn.name = $0 RETURN n LIMIT $1")
    List<DiseaseEntity> getDepartmentDisease(String departmentName,int num);

    @Query("MATCH(n:Disease)-[r:recommand_eat]->(nn:Food) WHERE nn.name = $0 RETURN n LIMIT $1")
    List<DiseaseEntity> getRecommandFoodDisease(String foodName,int num);

    @Query("MATCH(n:Disease)-[r:no_eat]->(nn:Food) WHERE nn.name = $0 RETURN n LIMIT $1")
    List<DiseaseEntity> getNotFoodDisease(String foodName,int num);

    @Query("MATCH (n:Disease) RETURN count(*)")
    Integer getDiseaseNum();

}
